// components/ng-like-step/index.js
const app = getApp()
const pathMap = {
  '-1': 'step1',
  0: 'step2',
  1: 'step3',
  2: 'step4',
}
const {
  investigateAdd
} = require("../../services/api/custom.js")
const { showToast } = require("../../utils/util")
Component({
  properties: {
    param: {
      type: Array,
      value: [],
    },
    active: {
      type: Number,
      value: -1,
    },
    showStep: {
      type: Boolean,
      value: false,
    },
    btnText: {
      type: String,
      value: app.data.$language.l98
    },
  },
  data:{
    l204:app.data.$language.l204
  },
  created(){
    // wx.EventChannel.on('languageChange', (val)=>{
    //   console.log(val);
    // })
  },
  methods: {
    onNextStepHandle() {
      if(this.data.active ==1||this.data.active ==2){
        if(this.data.param.length==0){
          showToast(app.data.$language.l203)
          return
        }
       
      }
      if (this.data.active < 3) {
        let name = pathMap[this.data.active]
        let url = `/subpackages/like/${name}/index` //
        wx.navigateTo({
          url
        })
      } else {
        // likePerfume
        let {sex,age,countryId,country,wearPerfume,usePerfume ,likePerfume,tagIds} = app.data.likeData
        investigateAdd({sex,age,countryId,country,wearPerfume,usePerfume ,likeSmell:likePerfume,tagIds}).then(res => {
          if (res.code == 0) {
            wx.setStorage({
              key: 'like',
              data: 1
            })
            this.onSkip()
          }
        })

      }
    },
    onSkip() {
      console.log(this.data.active);
      switch (this.data.active) {
        case -1:
          wx.navigateTo({
            url: '/subpackages/like/step1/index',
          })
          break;
        case 0:
        case 1:
          wx.navigateTo({
            url: '/subpackages/like/step3/index',
          })
          break;
        case 2:
          wx.navigateTo({
            url: '/subpackages/like/step4/index',
          })
          break;
        case 3:
          wx.reLaunch({
            url: '/pages/home/index',
          })
          break;
        default:
          break;
      }
    
    }
  },
})